public class Solution_387 {
    public int firstUniqChar(String s) {
        if (s.length() < 1) {
            return -1;
        }

        int[] set = new int[27];
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            set[s.charAt(i) - 'a'] += 1;
            if (set[s.charAt(ans) - 'a'] > 1) {
                do{
                    ans++;
                }while(ans < i && set[s.charAt(ans) - 'a'] != 1);
                if (ans >= s.length()) {return -1;}
                
            }
        }

        
        return ans;
    }

    public static void main(String[] args) {
        String s = "dddccdbba";
        int ans = new Solution_387().firstUniqChar(s);
        System.out.println(ans);
    }
}
